<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="tong.li&#39;s blog">
  <meta name="keyword" content="彤哥哥博客，95后技术爱好者,现就职于同程旅行/同程艺龙上海分公司，专注于互联网技术分享的平台。">
  
    <link rel="shortcut icon" href="/css/images/icon.png">
  
  <title>
    
      Linux运维-MySQL安装与配置 | 彤哥哥的博客
    
  </title>
  <link href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="https://cdn.staticfile.org/highlight.js/9.12.0/styles/tomorrow-night.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="https://cdn.staticfile.org/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


  
  
    
<script src="/js/local-search.js"></script>


<meta name="generator" content="Hexo 5.4.2"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>彤哥哥的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/series/" class="item-link">分类</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">项目</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于</a>
          
        </li>
      
      
        <li class="menu-item menu-item-search right-list">
    <a role="button" class="popup-trigger">
        <i class="fa fa-search fa-fw"></i>
    </a>
</li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/series/" class="menu-link">分类</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">项目</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于</a>
            
          </li>
        
      </ul>
    </div>
    
      <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
            <span class="search-icon">
                <i class="fa fa-search"></i>
            </span>
            <div class="search-input-container">
                <input autocomplete="off" autocapitalize="off"
                    placeholder="Please enter your keyword(s) to search." spellcheck="false"
                    type="search" class="search-input">
            </div>
            <span class="popup-btn-close">
                <i class="fa fa-times-circle"></i>
            </span>
        </div>
        <div id="search-result">
            <div id="no-result">
                <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
            </div>
        </div>
    </div>
</div>
    
  </div>
</header>

    <div id="article-banner">
  <h2>Linux运维-MySQL安装与配置</h2>
  <p class="post-date">2021-08-02</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="安装包下载"><a href="#安装包下载" class="headerlink" title="安装包下载"></a>安装包下载</h1><p>在官方download页面选择<a target="_blank" rel="noopener" href="https://downloads.mysql.com/archives/community/">MySQL5.7</a>安装包进行下载</p>
<p><img src="https://ltyeamin.github.io/imgs/2021/08/20210803153729.png" alt="MySQL下载页"></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]<span class="comment"># wget -c -t 0 https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz   # 通过wget命令进行断点下载</span></span><br><span class="line">--2021-08-03 15:38:45--  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz</span><br><span class="line">正在解析主机 downloads.mysql.com (downloads.mysql.com)... 137.254.60.14</span><br><span class="line">正在连接 downloads.mysql.com (downloads.mysql.com)|137.254.60.14|:443... 已连接。</span><br><span class="line">已发出 HTTP 请求，正在等待回应... 302 Found</span><br><span class="line">位置：https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz [跟随至新的 URL]</span><br><span class="line">--2021-08-03 15:38:46--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz</span><br><span class="line">正在解析主机 cdn.mysql.com (cdn.mysql.com)... 184.50.20.242</span><br><span class="line">正在连接 cdn.mysql.com (cdn.mysql.com)|184.50.20.242|:443... 已连接。</span><br><span class="line">已发出 HTTP 请求，正在等待回应... 200 OK</span><br><span class="line">长度：665389778 (635M) [application/x-tar-gz]</span><br><span class="line">正在保存至: “mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz”</span><br><span class="line"></span><br><span class="line"> 1% [&gt;                                                                                                               ] 7,080,892    443KB/s 剩余 24m 31s</span><br><span class="line"> 2% [=&gt;                                                                                                              ] 13,975,098   389KB/s 剩余 24m 25s</span><br></pre></td></tr></table></figure>

<h1 id="开始安装"><a href="#开始安装" class="headerlink" title="开始安装"></a>开始安装</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost bin]<span class="comment"># pwd  												 # 当前安装压缩包存放的目录</span></span><br><span class="line">/usr/local/bin</span><br><span class="line">[root@localhost bin]<span class="comment"># tar -xzvf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz   # 解压安装包</span></span><br><span class="line">[root@localhost bin]<span class="comment"># mv mysql-5.7.34-linux-glibc2.12-x86_64 ./mysql      	 # 对解压后的文件名重命名</span></span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost bin]<span class="comment"># useradd -r -s /sbin/nologin mysql    # 创建mysql用户</span></span><br><span class="line">[root@localhost bin]<span class="comment"># id mysql  						 # 查看mysql用户情况</span></span><br><span class="line">uid=997(mysql) gid=1000(mysql) 组=1000(mysql)</span><br><span class="line">[root@localhost bin]<span class="comment"># cd mysql/  					 # 进入到刚才解压的mysql目录中</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># mkdir data					 	 # 创建MySQL数据存储目录</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chown mysql:mysql data		  	  # 修改data目录的拥有者</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chmod 750 data                     # 修改data目录的权限</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># mkdir /var/run/mariadb/            # 创建mariadb目录</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chown -R mysql:mysql /var/run/mariadb/ # 给mariadb目录设置组</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># mkdir /var/log/mariadb/            # 创建mariadb日志目录</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># touch /var/log/mariadb/mariadb.log # 创建mariadb日志文件</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chown -R mysql:mysql /var/log/mariadb/ # 设置mariadb日志目录组</span></span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/bin/mysql # 初始化mysql，并得到密码</span></span><br><span class="line">2021-08-03T07:57:11.664523Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation <span class="keyword">for</span> more details).</span><br><span class="line">2021-08-03T07:57:11.849687Z 0 [Warning] InnoDB: New <span class="built_in">log</span> files created, LSN=45790</span><br><span class="line">2021-08-03T07:57:11.885631Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.</span><br><span class="line">2021-08-03T07:57:11.950348Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 68d7a83f-f430-11eb-a7b5-00155d565000.</span><br><span class="line">2021-08-03T07:57:11.955619Z 0 [Warning] Gtid table is not ready to be used. Table <span class="string">&#x27;mysql.gtid_executed&#x27;</span> cannot be opened.</span><br><span class="line">2021-08-03T07:57:12.580948Z 0 [Warning] CA certificate ca.pem is self signed.</span><br><span class="line">2021-08-03T07:57:12.746348Z 1 [Note] A temporary password is generated <span class="keyword">for</span> root@localhost: CuLgE+pxr0Xv</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># vim support-files/mysql.server  # 修改mysql服务器配置文件，主要修改basedir和datadir目录</span></span><br><span class="line">basedir=/usr/local/bin/mysql</span><br><span class="line">datadir=/usr/local/bin/mysql/data</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># cp support-files/mysql.server /etc/init.d/mysql  # 拷贝脚本到/etc/init.d下，注册为系统服务</span></span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]# service mysql start   # 启动</span><br><span class="line">Warning: mysql.service changed on disk. Run &#x27;systemctl daemon-reload&#x27; to reload units.</span><br><span class="line">Starting MySQL. SUCCESS! </span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># ./bin/mysql -uroot -p  			# 初始化登录测试，登录密码是上述的初始化默认密码</span></span><br><span class="line">Enter password: </span><br><span class="line">Welcome to the MySQL monitor.  Commands end with ; or \g.</span><br><span class="line">Your MySQL connection <span class="built_in">id</span> is 2</span><br><span class="line">Server version: 5.7.34-<span class="built_in">log</span></span><br><span class="line"></span><br><span class="line">Copyright (c) 2000, 2021, Oracle and/or its affiliates.</span><br><span class="line"></span><br><span class="line">Oracle is a registered trademark of Oracle Corporation and/or its</span><br><span class="line">affiliates. Other names may be trademarks of their respective</span><br><span class="line">owners.</span><br><span class="line"></span><br><span class="line">Type <span class="string">&#x27;help;&#x27;</span> or <span class="string">&#x27;\h&#x27;</span> <span class="keyword">for</span> <span class="built_in">help</span>. Type <span class="string">&#x27;\c&#x27;</span> to clear the current input statement.</span><br><span class="line"></span><br><span class="line">mysql&gt; <span class="built_in">set</span> password = password(<span class="string">&#x27;123456&#x27;</span>);             <span class="comment"># 修改密码为123456</span></span><br><span class="line">mysql&gt; GRANT ALL ON *.* TO root@<span class="string">&#x27;%&#x27;</span> IDENTIFIED BY <span class="string">&#x27;123456&#x27;</span> WITH GRANT OPTION;  <span class="comment"># 设置为远程登录</span></span><br><span class="line">Query OK, 0 rows affected, 1 warning (0.00 sec)</span><br><span class="line">mysql&gt; flush privileges;                              <span class="comment"># 刷新账户配置更改</span></span><br><span class="line">mysql&gt; show variables like <span class="string">&#x27;character_set_%&#x27;</span>;         <span class="comment"># 查看当前MySQL实例的默认编码配置</span></span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">| Variable_name            | Value                                |</span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">| character_set_client     | utf8                                 |</span><br><span class="line">| character_set_connection | utf8                                 |</span><br><span class="line">| character_set_database   | latin1                               |</span><br><span class="line">| character_set_filesystem | binary                               |</span><br><span class="line">| character_set_results    | utf8                                 |</span><br><span class="line">| character_set_server     | latin1                               |</span><br><span class="line">| character_set_system     | utf8                                 |</span><br><span class="line">| character_sets_dir       | /usr/local/bin/mysql/share/charsets/ |</span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">8 rows <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</span><br><span class="line">mysql&gt; show variables like <span class="string">&#x27;%query%&#x27;</span>;                   <span class="comment"># 查看慢日志是否开启</span></span><br><span class="line">+------------------------------+----------------------------------------------+</span><br><span class="line">| Variable_name                | Value                                        |</span><br><span class="line">+------------------------------+----------------------------------------------+</span><br><span class="line">| binlog_rows_query_log_events | OFF                                          |</span><br><span class="line">| ft_query_expansion_limit     | 20                                           |</span><br><span class="line">| have_query_cache             | YES                                          |</span><br><span class="line">| long_query_time              | 10.000000                                    |</span><br><span class="line">| query_alloc_block_size       | 8192                                         |</span><br><span class="line">| query_cache_limit            | 1048576                                      |</span><br><span class="line">| query_cache_min_res_unit     | 4096                                         |</span><br><span class="line">| query_cache_size             | 1048576                                      |</span><br><span class="line">| query_cache_type             | OFF                                          |</span><br><span class="line">| query_cache_wlock_invalidate | OFF                                          |</span><br><span class="line">| query_prealloc_size          | 8192                                         |</span><br><span class="line">| slow_query_log               | OFF                                          |</span><br><span class="line">| slow_query_log_file          | /usr/local/bin/mysql/data/localhost-slow.log |</span><br><span class="line">+------------------------------+----------------------------------------------+</span><br><span class="line">13 rows <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</span><br><span class="line">mysql&gt; <span class="built_in">exit</span>					                       <span class="comment"># 退出登录</span></span><br><span class="line">Bye</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># vim /etc/my.cnf   # 編輯MySQL配置文件，修改编码、端口号</span></span><br><span class="line">[mysqld]</span><br><span class="line">collation_server = utf8_general_ci</span><br><span class="line">character_set_server = utf8</span><br><span class="line">datadir=/usr/local/bin/mysql/data</span><br><span class="line">port=3306</span><br><span class="line">socket=/var/lib/mysql/mysql.sock</span><br><span class="line"><span class="comment"># Disabling symbolic-links is recommended to prevent assorted security risks</span></span><br><span class="line">symbolic-links=0</span><br><span class="line">log-bin=mysql-bin </span><br><span class="line">binlog-format=ROW </span><br><span class="line">server_id=1 </span><br><span class="line">max_connections=1000</span><br><span class="line">slow_query_log=ON                                           <span class="comment">#开启慢日志</span></span><br><span class="line">slow_query_log_file=/usr/local/bin/mysql/data/slow.log      <span class="comment">#日志存放位置</span></span><br><span class="line">long_query_time=5                                           <span class="comment">#超时时间5秒（超过5秒就会被记录下来）</span></span><br><span class="line"><span class="comment"># Settings user and group are ignored when systemd is used.</span></span><br><span class="line"><span class="comment"># If you need to run mysqld under a different user or group,</span></span><br><span class="line"><span class="comment"># customize your systemd unit file for mariadb according to the</span></span><br><span class="line"><span class="comment"># instructions in http://fedoraproject.org/wiki/Systemd</span></span><br><span class="line">[client]</span><br><span class="line">default-character-set=utf8</span><br><span class="line">socket=/var/lib/mysql/mysql.sock</span><br><span class="line"></span><br><span class="line">[mysqld_safe]</span><br><span class="line">log-error=/var/log/mariadb/mariadb.log</span><br><span class="line">pid-file=/var/run/mariadb/mariadb.pid</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">init_connect=<span class="string">&#x27;SET collation_connection = utf8_unicode_ci&#x27;</span></span><br><span class="line">init_connect=<span class="string">&#x27;SET NAMES utf8&#x27;</span></span><br><span class="line">character-set-server=utf8</span><br><span class="line">collation-server=utf8_unicode_ci</span><br><span class="line">skip-character-set-client-handshake</span><br><span class="line"></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># include all files from the config directory</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line">!includedir /etc/my.cnf.d</span><br></pre></td></tr></table></figure>




<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># ./bin/mysql -uroot -p  # 重新登录查看再次查看编码、慢日志设置</span></span><br><span class="line">Enter password: </span><br><span class="line">Welcome to the MySQL monitor.  Commands end with ; or \g.</span><br><span class="line">Your MySQL connection <span class="built_in">id</span> is 2</span><br><span class="line">Server version: 5.7.34-<span class="built_in">log</span> MySQL Community Server (GPL)</span><br><span class="line"></span><br><span class="line">Copyright (c) 2000, 2021, Oracle and/or its affiliates.</span><br><span class="line"></span><br><span class="line">Oracle is a registered trademark of Oracle Corporation and/or its</span><br><span class="line">affiliates. Other names may be trademarks of their respective</span><br><span class="line">owners.</span><br><span class="line"></span><br><span class="line">Type <span class="string">&#x27;help;&#x27;</span> or <span class="string">&#x27;\h&#x27;</span> <span class="keyword">for</span> <span class="built_in">help</span>. Type <span class="string">&#x27;\c&#x27;</span> to clear the current input statement.</span><br><span class="line"></span><br><span class="line">mysql&gt; show variables like <span class="string">&#x27;character_set_%&#x27;</span>;</span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">| Variable_name            | Value                                |</span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">| character_set_client     | utf8                                 |</span><br><span class="line">| character_set_connection | utf8                                 |</span><br><span class="line">| character_set_database   | utf8                                 |</span><br><span class="line">| character_set_filesystem | binary                               |</span><br><span class="line">| character_set_results    | utf8                                 |</span><br><span class="line">| character_set_server     | utf8                                 |</span><br><span class="line">| character_set_system     | utf8                                 |</span><br><span class="line">| character_sets_dir       | /usr/local/bin/mysql/share/charsets/ |</span><br><span class="line">+--------------------------+--------------------------------------+</span><br><span class="line">8 rows <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</span><br><span class="line">mysql&gt; show variables like <span class="string">&#x27;%query%&#x27;</span>;</span><br><span class="line">+------------------------------+------------------------------------+</span><br><span class="line">| Variable_name                | Value                              |</span><br><span class="line">+------------------------------+------------------------------------+</span><br><span class="line">| binlog_rows_query_log_events | OFF                                |</span><br><span class="line">| ft_query_expansion_limit     | 20                                 |</span><br><span class="line">| have_query_cache             | YES                                |</span><br><span class="line">| long_query_time              | 5.000000                           |</span><br><span class="line">| query_alloc_block_size       | 8192                               |</span><br><span class="line">| query_cache_limit            | 1048576                            |</span><br><span class="line">| query_cache_min_res_unit     | 4096                               |</span><br><span class="line">| query_cache_size             | 1048576                            |</span><br><span class="line">| query_cache_type             | OFF                                |</span><br><span class="line">| query_cache_wlock_invalidate | OFF                                |</span><br><span class="line">| query_prealloc_size          | 8192                               |</span><br><span class="line">| slow_query_log               | ON                                 |</span><br><span class="line">| slow_query_log_file          | /usr/local/bin/mysql/data/slow.log |</span><br><span class="line">+------------------------------+------------------------------------+</span><br><span class="line">13 rows <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</span><br></pre></td></tr></table></figure>

<h1 id="服务命令"><a href="#服务命令" class="headerlink" title="服务命令"></a>服务命令</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># service mysql start       # MySQL服务启动命令，可以通过systemctl start mysql达到相同的结果</span></span><br><span class="line">Starting MySQL. SUCCESS!</span><br><span class="line">[root@localhost mysql]<span class="comment"># service mysql restart     # MySQL服务重启命令，可以通过systemctl restart mysql达到相同的结果</span></span><br><span class="line">Shutting down MySQL.. SUCCESS! </span><br><span class="line">Starting MySQL. SUCCESS! </span><br><span class="line">[root@localhost mysql]<span class="comment"># service mysql status      # MySQL服务状态命令，可以通过systemctl status mysql达到相同的结果</span></span><br><span class="line"> SUCCESS! MySQL running (4538)</span><br><span class="line">[root@localhost mysql]<span class="comment"># service mysql stop 	      # MySQL服务关闭命令，可以通过systemctl stop mysql达到相同的结果</span></span><br><span class="line">Shutting down MySQL.. SUCCESS! </span><br></pre></td></tr></table></figure>

<h1 id="开机自启"><a href="#开机自启" class="headerlink" title="开机自启"></a>开机自启</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost mysql]<span class="comment"># chkconfig --add mysql     # 添加开机自启服务</span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chkconfig mysql on        # 开机自启开关 </span></span><br><span class="line">[root@localhost mysql]<span class="comment"># chkconfig --list          # 开机自启列表项</span></span><br><span class="line"></span><br><span class="line">注：该输出结果只显示 SysV 服务，并不包含</span><br><span class="line">原生 systemd 服务。SysV 配置数据</span><br><span class="line">可能被原生 systemd 配置覆盖。 </span><br><span class="line"></span><br><span class="line">      要列出 systemd 服务，请执行 <span class="string">&#x27;systemctl list-unit-files&#x27;</span>。</span><br><span class="line">      查看在具体 target 启用的服务请执行</span><br><span class="line">      <span class="string">&#x27;systemctl list-dependencies [target]&#x27;</span>。</span><br><span class="line"></span><br><span class="line">mysql          	0:关	1:关	2:开	3:开	4:开	5:开	6:关</span><br><span class="line">netconsole     	0:关	1:关	2:关	3:关	4:关	5:关	6:关</span><br><span class="line">network        	0:关	1:关	2:开	3:开	4:开	5:开	6:关</span><br><span class="line">redis_6379     	0:关	1:关	2:开	3:开	4:开	5:开	6:关</span><br></pre></td></tr></table></figure>

</section>
    <!-- Tags START -->
    
      <div class="tags">
        <span>Tags:</span>
        
  <a href="/tags#Linux" >
    <span class="tag-code">Linux</span>
  </a>

      </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2021/08/01/Linux%E8%BF%90%E7%BB%B4-%E5%AE%9E%E7%94%A8%E7%9A%84%E5%B0%8F%E8%84%9A%E6%9C%AC/">
        <span class="nav-arrow">← </span>
        
          Linux运维-实用的小脚本
        
      </a>
    
    
      <a class="nav-right" href="/2021/08/03/Linux%E5%9F%BA%E7%A1%80-%E9%80%9A%E8%BF%87inode%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6/">
        
          Linux基础-通过inode删除文件
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Utterances START -->
      <div id="utterances"></div>
      <script src="https://utteranc.es/client.js"
        repo="ltyeamin/blogtalks"
        issue-term="pathname"
        theme="github-light"
        crossorigin="anonymous"
        async></script>    
      <!-- Utterances END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#%E5%AE%89%E8%A3%85%E5%8C%85%E4%B8%8B%E8%BD%BD"><span class="toc-nav-text">安装包下载</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#%E5%BC%80%E5%A7%8B%E5%AE%89%E8%A3%85"><span class="toc-nav-text">开始安装</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#%E6%9C%8D%E5%8A%A1%E5%91%BD%E4%BB%A4"><span class="toc-nav-text">服务命令</span></a></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#%E5%BC%80%E6%9C%BA%E8%87%AA%E5%90%AF"><span class="toc-nav-text">开机自启</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://example.com/2021/08/02/Linux运维-MySQL安装与配置/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', '/css/images/error_icon.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== '/css/images/error_icon.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>






    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2024 | Proudly powered by <a href="https://hexo.io" target="_blank">Hexo</a>
    <br>
    Theme by <a target="_blank" rel="noopener" href="https://github.com/ltyeamin">tong.li</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("https://cdn.staticfile.org/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("https://cdn.staticfile.org/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      hljs.configure({useBR: true});
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->



<script src='https://cdn.staticfile.org/mermaid/8.11.2/mermaid.min.js'></script>



<script src="/js/script.js"></script>


  </body>
</html>